package thread.threaddemo;

/**
 * @Author: wenjingyuan
 * @Date: 2022/11/05/21:20
 * @Description:守护线程示例
 */
public class ThreadDemoByDaemon {
    public static void main(String[] args) throws InterruptedException {
        Thread t=Thread.currentThread();
        System.out.println("是否是守护线程："+t.isDaemon());
        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+"是否是守护线程:"+Thread.currentThread().isDaemon());
                Thread t1=new Thread(new Runnable() {
                    @Override
                    public void run() {
                        System.out.println(Thread.currentThread().getName()+"是否是守护线程:"+Thread.currentThread().isDaemon());
                    }
                },"子线程的子线程");
                t1.start();
            }
        },"子线程1");
        thread.setDaemon(true);
        thread.start();
        //让主线程等一下
        Thread.sleep(1000);
    }
}
